package org.rugby.online.impl;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.Locale;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.rugby.online.core.humans.RboPlayerLevel;
import org.rugby.online.core.skills.RboSkill;
import org.rugby.online.core.skills.RboSkillType;
import org.rugby.online.impl.DefaultPlayer;
import org.rugby.online.impl.DefaultSkill;

public class DefaultPlayerTest {
	
	private DefaultPlayer player;
	
	@Before
	public void setUp() {
		this.player = new DefaultPlayer(Locale.FRENCH);
	}
	
	
	@Test
	public void testSetLevel() {
		this.player.setLevel(RboPlayerLevel.AMATEUR);
		RboPlayerLevel level = this.player.getLevel();
		assertNotNull(level);
		assertTrue(level.equals(RboPlayerLevel.AMATEUR));
	}

	@Test
	public void testGetWeight() {
		int weight = this.player.getWeight();
		assertNotNull(weight);
		assertTrue(weight >= DefaultPlayer.MINIMAL_WEIGHT);
		assertTrue(weight <= DefaultPlayer.MAXIMAL_WEIGHT);
		System.out.println("[TEST WEIGHT] > " + String.valueOf(weight));
	}

	@Test
	public void testGetHeight() {
		int height = this.player.getHeight();
		assertNotNull(height);
		assertTrue(height >= DefaultPlayer.MINIMAL_HEIGHT);
		assertTrue(height <= DefaultPlayer.MAXIMAL_HEIGHT);
		System.out.println("[TEST HEIGHT] > " + String.valueOf(height));
	}

	@Test
	public void testGetSkillMap() {
		Map<String, RboSkill> map = this.player.getSkillMap();
		assertNotNull(map);
		for (String key : map.keySet()) {
			RboSkill skill = map.get(key);
			assertNotNull(skill);
			RboSkillType type = skill.getType();
			assertNotNull(type);
			int level = skill.getLevel();
			assertNotNull(level);
			assertTrue(level >= DefaultSkill.MIN_VALUE);
			assertTrue(level <= DefaultSkill.MAX_INIT_VALUE);
			System.out.println("[TEST SKILL] > " + key + " : " + String.valueOf(level));
		}
	}

	@Test
	public void testGetLevel() {
		RboPlayerLevel level = this.player.getLevel();
		assertNotNull(level);
		assertTrue(level.equals(RboPlayerLevel.AMATEUR));
	}

	@Test
	public void testGetNationality() {
		assertTrue(this.player.getNationality().equals(Locale.FRENCH));
	}

	@Test
	public void testGetFirstName() {
		String name = this.player.getFirstName();
		assertNotNull(name);
		assertTrue(name.length() > 0);
		System.out.println("[TEST NAME] > " + name);
	}

	@Test
	public void testAge() {
		short age = this.player.getAge();
		assertNotNull(age);
		assertTrue(age >= DefaultPlayer.MINIMAL_AGE);
		assertTrue(age <= DefaultPlayer.MAXIMAL_AGE);
		System.out.println("[TEST AGE] > " + String.valueOf(age));
	}

	@Test
	public void testPopUpAge() {
		short age = this.player.getAge();
		this.player.popUpAge();
		short ageAfter = this.player.getAge();
		assertTrue(ageAfter - age == 1);
	}

	@Test
	public void testGetName() {
		String name = this.player.getName();
		assertNotNull(name);
		assertTrue(name.length() > 0);
		System.out.println("[TEST NAME] > " + name);
	}

	@Test
	public void testGetId() {
		long id = this.player.getId();
		assertNotNull(id);
		System.out.println("[TEST ID] > " + String.valueOf(id));
	}

}
